package com.smh;

import java.util.ArrayDeque;

/**
 * @author shiminghui
 * @date 2025/2/17 9:51
 * @description: TODO
 */
public class _020_队列实现栈 {

    class MyStack {

        private final ArrayDeque<Integer> queue = new ArrayDeque<>();

        public MyStack() {

        }

        public void push(int x) {
            int size = queue.size();
            queue.add(x);
            for (int i = 0; i < size; i++) {
                queue.add(queue.remove());
            }
        }

        public int pop() {
            return queue.remove();
        }

        public int top() {
            if (queue.isEmpty()) {
                return -1;
            }
            return queue.peek();
        }

        public boolean empty() {
            return queue.isEmpty();
        }
    }

}
